<template>
  <div class="dashboard-container">
    <el-row :gutter="20">
      <el-col :xs="24" :sm="6" :span="6">
        <el-card class="box-card" :body-style="{ padding: '5px 20px', minHeight: '230px' }">
          <div class="header">
            <span>总答题数量</span>
            <el-tooltip class="item" effect="dark" content="指标说明" placement="top">
              <i class="el-icon-warning"></i>
            </el-tooltip>
          </div>
          <div class="total">
            260,560
          </div>
          <div class="trends">
            <span>周同比 12% <i class="el-icon-caret-top"></i></span>
            <span>日环比 11% <i class="el-icon-caret-bottom"></i></span>
          </div>
          <div class="hr"></div>
          <div class="footer"><span>日答题数量</span> <span>12,423</span></div>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="6" :span="6">
        <el-card class="box-card" :body-style="{ padding: '5px 20px', minHeight: '230px' }">
          <div class="header">
            <span>试题方向</span>
            <el-tooltip class="item" effect="dark" content="指标说明" placement="top">
              <i class="el-icon-warning"></i>
            </el-tooltip>
          </div>
          <div class="chart">
            <radar-chart></radar-chart>
          </div>
          <div class="hr"></div>
          <div class="footer"><span>试题库数量</span> <span>10,234</span></div>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="6" :span="6">
        <el-card class="box-card" :body-style="{ padding: '5px 20px', minHeight: '230px' }">
          <div class="header">
            <span>试题学科分布</span>
            <el-tooltip class="item" effect="dark" content="指标说明" placement="top">
              <i class="el-icon-warning"></i>
            </el-tooltip>
          </div>
          <div class="chart">
            <pie-chart></pie-chart>
          </div>
          <div class="hr"></div>
          <div class="footer"><span>前端试题数量</span> <span>5,234</span></div>
        </el-card>
      </el-col>
      <el-col :xs="24" :sm="6" :span="6">
        <el-card class="box-card" :body-style="{ padding: '5px 20px', minHeight: '230px' }">
          <div class="header">
            <span>上周试题新增</span>
            <el-tooltip class="item" effect="dark" content="指标说明" placement="top">
              <i class="el-icon-warning"></i>
            </el-tooltip>
          </div>
          <div class="chart">
            <bar-chart></bar-chart>
          </div>
          <div class="hr"></div>
          <div class="footer"><span>上周新增总量</span> <span>1,234</span></div>
        </el-card>
      </el-col>
    </el-row>

    <br />
    <!-- 销售表 -->
    <el-card class="sales-card">
      <div style="position: absolute; top: 20px; right: 20px; color: #999;">
        前端与java学科试题走势图
      </div>
      <el-tabs v-model="activeName">
        <el-tab-pane label="前端学科" name="newVisitis"></el-tab-pane>
        <el-tab-pane label="JAVA学科" name="messages"></el-tab-pane>
        <el-row :gutter="20">
          <el-col :xs="24" :sm="16">
            <div class="chart">
              <line-chart :chartData="lineChartData[activeName]"></line-chart>
            </div>
          </el-col>
          <el-col :xs="24" :sm="8">
            <div class="table">
              <h4>学科试题数量排名</h4>
              <ul>
                <li>
                  <el-row class="row" v-for="(item, index) in salesTable" :key="'sals-' + index">
                    <el-col :span="3">
                      <div v-bind:class="[item.num > 3 ? 'light' : '', 'circular']">
                        {{ item.num }}
                      </div>
                    </el-col>
                    <el-col :span="16">{{ item.title }}</el-col>
                    <el-col :span="5">{{ item.val }}</el-col>
                  </el-row>
                </li>
              </ul>
            </div>
          </el-col>
        </el-row>
      </el-tabs>
    </el-card>
    <!-- 销售表 /-->
  </div>
</template>

<script setup>
import RadarChart from './components/RadarChart.vue'
import PieChart from './components/PieChart.vue'
import BarChart from './components/BarChart.vue'
import LineChart from './components/LineChart.vue'
import { ref } from 'vue'

// 线状图
const activeName = ref('newVisitis')
const lineChartData = {
  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165, 100, 120, 161, 134, 105, 160, 165]
  },
  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140, 105, 160, 165, 100, 120, 161, 134]
  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130]
  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130]
  }
}

const salesTable = [
  { num: 1, title: '前端', val: '5,234' },
  { num: 2, title: 'java', val: '3,210' },
  { num: 3, title: '大数据', val: '1,294' },
  { num: 4, title: 'c++', val: '1,001' },
  { num: 5, title: 'UI', val: '934' },
  { num: 6, title: 'php', val: '856' },
  { num: 7, title: 'python', val: '403' },
  { num: 8, title: '测试', val: '122' }
]
</script>

<style lang="scss" scoped>
.dashboard-container {
  margin: 10px;
}

.box-card {
  padding: 5px 10px;
  .header {
    height: 25px;
    span {
      color: #97a8be;
      font-size: 14px;
    }
    .item {
      color: #97a8be;
      float: right;
      padding: 3px 0;
    }
  }
  // 总销售额
  .total {
    font-size: 30px;
    height: 140px;
    line-height: 140px;
    padding-left: 20px;
  }
  .trends {
    height: 22px;
    font-size: 14px;
    span {
      display: inline;
      i {
        color: red;
      }
    }
    span:last-child {
      margin-left: 20px;
      display: inline;
      i {
        color: green;
      }
    }
  }
  .chart {
    height: 160px;
  }
  .hr {
    border-top: 1px solid #e8e8e8;
    margin: 0px 0px 10px 0px;
  }
  .footer {
    span {
      font-size: 14px;
      line-height: 22px;
    }
    span:last-child {
      margin-left: 8px;
      color: rgba(0, 0, 0, 0.85);
    }
  }
  // 总销售额 end
}

// 销售额
.sales-card {
  position: relative;
  .header {
    position: absolute;
    right: 20px;
    top: 15px;
    z-index: 1;
  }
  .chart {
    width: 100%;
    height: 100%;
  }
  .table {
    color: rgba(0, 0, 0, 0.65);
    display: block;
    h4 {
      color: #000;
      font-weight: 500;
    }
    ul {
      list-style: none;
      margin: 0px;
      padding: 0px;
      .row {
        margin-bottom: 10px;
      }
    }
    .circular {
      width: 20px;
      height: 20px;
      background-color: #314659;
      color: #fff;
      text-align: center;
      font-size: 12px;
      line-height: 20px;
      font-weight: 600;
      border-radius: 50%;
    }
    .light {
      background-color: #f5f5f5;
      color: rgba(0, 0, 0, 0.65);
    }
  }
}

// 线上热门搜索
.hots {
  height: 400px;
  position: relative;
  .header {
    color: #97a8be;
    .ops {
      position: absolute;
      right: 20px;
    }
  }
  .pagination {
    position: absolute;
    right: 12px;
    bottom: 5px;
  }
  .chart {
    height: 300px;
  }
}

// 周搜索
.month-card {
  height: 400px;
  .chart {
    height: 300px;
  }
}
</style>
